package com.sino.operation.service.basic;

import com.sino.operation.service.impl.SysTellerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Title: RedisTaskService
 * @Description: redis任务关联服务服务部分
 * @Author dengls
 * @date 2021/10/14 10:43
 */
@Service
public class RedisTaskUserService {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private SysTellerServiceImpl sysTellerService;

    /**
     * 在redis存入用户信息
     *
     * @param tellPost
     * @param tellCode
     */
    public void addUserData(String tellPost, String tellCode) {
        List<String> transTypeList = sysTellerService.getTransTypeByTellerCode(tellCode);
        SetOperations<String, String> ops = stringRedisTemplate.opsForSet();
        transTypeList.forEach(item -> {
            ops.add("commonData-" + tellPost + "-" + item, tellCode);
        });
    }

    /**
     * 移除redis里的用户信息
     *
     * @param tellPost
     * @param tellCode
     */
    public void removeUserData(String tellPost, String tellCode) {
        List<String> transTypeList = sysTellerService.getTransTypeByTellerCode(tellCode);
        SetOperations<String, String> ops = stringRedisTemplate.opsForSet();
        transTypeList.forEach(item -> {
            ops.remove("commonData-" + tellPost + "-" + item, tellCode);
        });
    }
}
